package com.example.phonephone;

import com.example.phonephone.R;

import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.ContactsContract;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.telephony.SmsMessage;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends Activity {
//public class MainActivity extends BroadcastReceiver {
//	
//    @Override
//	public void onReceive(Context context, Intent intent) {
//        //---get the SMS message passed in---
//        Bundle bundle = intent.getExtras();        
//        SmsMessage[] msgs = null;
//        String str = "";            
//        if (bundle != null)
//        {
//            //---retrieve the SMS message received---
//            Object[] pdus = (Object[]) bundle.get("pdus");
//            msgs = new SmsMessage[pdus.length];            
//            for (int i=0; i<msgs.length; i++){
//                msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                
//                str += "SMS from " + msgs[i].getOriginatingAddress();                     
//                str += " :";
//                str += msgs[i].getMessageBody().toString();
//                str += "\n";        
//            }
//            //---display the new SMS message---
//            Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
//        }
//	}
//
//	@Override
//	public IBinder peekService(Context myContext, Intent service) {
//		// TODO Auto-generated method stub
//		return super.peekService(myContext, service);
//	}
//
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        String phone_number = "0545909707";
        String key_code = "**21*" + phone_number + "#";
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri uri = Uri.fromParts("tel", key_code, "#"); 
        intent.setData(uri);
        startActivity(new Intent(Intent.ACTION_CALL, uri));
//        getDetails();

	}
        
        
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
//    private void getDetails(){
//        Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
//        ContentResolver cr = getContentResolver();
//        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
//        String[] projection    = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
//                            ContactsContract.CommonDataKinds.Phone.NUMBER };
//        Cursor names = getContentResolver().query(uri, projection, null, null, null);
//        int indexName = names.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
//        int indexNumber = names.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
//        names.moveToFirst();
//        do {
//           String name   = names.getString(indexName);
//           Log.e("Name new:", name);
//           String number = names.getString(indexNumber);
//           Log.e("Number new:","::"+number);
//        } while (names.moveToNext());
//    }
    
}
